<?php
include("connect.php");
?>

<?php
$css = '<link rel="stylesheet" type="text/css" media="all" href="asset/css/class_sellbook.css">';
$title = 'Sell book';
$page_name = 'sell_book';
$autofillstatus = 0;
$bookid = 0;
$type="new";
$cond1[0] = 'checked="checked"';
$cond2[0] = 'checked="checked"';
$cond3[0] = 'checked="checked"';
$cond4[0] = 'checked="checked"';
if(isset($_REQUEST["check"]))
{
	$title = "Edit Book";
	$userbookid=$_REQUEST['userbookid'];
	$sql = "select b.book_title, b.book_author,a.price,a.condition1,a.condition2,a.condition3,a.condition4,a.book_id from t_user_book a";
	$sql .= " inner join m_book b on a.book_id=b.book_id";
	$sql .= " where a.user_book_id=".$userbookid;
	$retval = mysql_query( $sql, $con );
	if(! $retval )
	{
		die('Could not get data: ' . mysql_error());
	}
	while($row = mysql_fetch_array($retval))
	{
		$title = $row[0];
		$author = $row[1];
		$price = $row[2];
		$condition1 = $row[3]-1;
		$condition2 = $row[4]-1;
		$condition3 = $row[5]-1;
		$condition4 = $row[6]-1;
		$bookid=$row[7];
	}
	$cond1[0]="";
	$cond1[$condition1]='checked="checked"';
	$cond2[0]="";
	$cond2[$condition2]='checked="checked"';
	$cond3[0]="";
	$cond3[$condition3]='checked="checked"';
	$cond4[0]="";
	$cond4[$condition4]='checked="checked"';
	$type="edit";
	
	

}
?>

<?php
$sql = "select user_category from m_user where user_id=".$_SESSION['userid'];
$retval = mysql_query( $sql, $con );
while($row = mysql_fetch_array($retval))
	{
		$user_category = $row[0];
	}
if(isset($_SESSION["userid"]))
	{
		if($user_category ==9)
		{
			include("header_loggedinadmin.php");
		}else
		{
			include("header_loggedin.php");
		}
	}
else
{
	echo '<script>';
		echo "alert('Please Login!');";
		echo 'window.location = "index.php"';
		echo '</script>';}?>

<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">

$(document).ready(function() {
 		$('#show_sub_categories').hide();
		  $('#show_sub_categories2').hide();
		$('#search_category_id').change(function(){
		 $('#show_sub_categories').fadeOut();
		  $('#show_sub_categories2').fadeOut();
		$.post("get_child_category.php", {
			parent_id: $('#search_category_id').val(),
		}, function(response){
			
			setTimeout("finishAjax('show_sub_categories', '"+escape(response)+"')", 400);
			setTimeout("finishAjax('show_sub_categories2', '"+escape(response)+"')", 400);
		});
		return false;
	});	
});

function finishAjax(id, response){
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
} 

function alert_id()
{
	if($('#search_category_id').val()=='0')
	{
	alert('Please select a category.');
	return false;
	}
	if($('#show_sub_categories').val() == '0')
	{alert('Please select a sub category.');
	return false;
	}
	return true;
}

</script>

<div id="blue_bg">
	<div id="main">
        <div class="wrapper">
        	<div id="content">
            	<div id="white_box">
                	<h3 class="flag_long">SELL BOOK</h3>
                	<form enctype="multipart/form-data" action=sell_book_check.php method="post" onsubmit="return alert_id();">
                	<input type="hidden" name="type" value="<?php echo $type;?>" />
                	<input type="hidden" name="userbookid" value="<?php echo $userbookid;?>" />
                    <table>
                        <tr>
                        <!-- kalo nanti ditambahin autofillnya, kalo jln, bookid-nya ada isinya, kalo ndak tetep 0, biar memudahkan nanti waktu insert ke database. kalo ada nilainya tidak perlu tambah di M_BOOK, kalo 0 harus tambah di M_BOOK-->
                        <input type="hidden"name="bookid" value=<?php echo $bookid;?> />
                            <td>Title</td>
                            <td width="50px"></td>
                            <td><input type="text" name="title" size="50" value="<?php echo $title;?>"/></td>
                        </tr>
                        <tr>
                            <td>Author</td>
                            <td width="50px"></td>
                            <td><input type="text" name="author" size="50" value="<?php echo $author;?>"/></td>
                        </tr>
                        <tr>
                            <td>Price</td>
                            <td width="50px"></td>
                            <td><input type="text" name="price" size="15" value="<?php echo $price;?>" /></td>
                        </tr>
                        <tr>
                            <td>Category</td>
                            <td width="50px"></td>
                            <td>
                             <?php 
   								 echo  '<select name="course" class="droplist" id="search_category_id"><option value="0" selected="selected"> </option>';

   								 $sql = "select category_id, category_name from t_category";
    							 $result = mysql_query($sql);
								 while($row = mysql_fetch_array($result))
	                             {
		 							echo '<option class="dropoption" value="'.$row[0].'">'.$row[1].'</option>';
								}
								echo "</select>";
    						?>
    						 <!--MAJOR 1-->
   								 <select name="major1" class="droplist" id="show_sub_categories"></select>
   							 <!--MAJOR 2-->
  								  <select name="major2" class="droplist" id="show_sub_categories2"></select>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td width="50px"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>Upload Picture</td>
                            <td width="50px"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td>1'st picture</td>
                            <td width="50px"></td>
                            <td><input type="file" name="img1" size="40"></td>
                        </tr>
                        <tr>
                            <td>2'nd picture</td>
                            <td width="50px"></td>
                            <td><input type="file" name="img2" size="40"></td>
                        </tr>
                        <tr>
                            <td>3'rd picture</td>
                            <td width="50px"></td>
                            <td><input type="file" name="img3" size="40"></td>
                        </tr>
                         <tr>
                            <td>Book Description</td>
                            <td width="50px"></td>
                            <td></td>
                        </tr>
                        <tr>
                        	<td>Binding</td>
                        	<td width="50px"></td>
                        	<td>
                        		 <input type="radio" name="binding" value="4" class="description" <?php echo $cond1[3];?> />&nbsp;as new&nbsp;
  								 <input type="radio" name="binding" value="3" class="description" <?php echo $cond1[2];?> />&nbsp;good&nbsp;
   								 <input type="radio" name="binding" value="2" class="description" <?php echo $cond1[1];?> />&nbsp;incomplete&nbsp;
   								 <input type="radio" name="binding" value="1" class="description" <?php echo $cond1[0];?> />&nbsp;broken&nbsp;
							</td>
                        </tr>
                        <tr>
                        	<td>Cover</td>
                        	<td width="50px"></td>
                        	<td> 
                        		 <input type="radio" name="cover" value="4" class="description"  <?php echo $cond2[3];?> />&nbsp;as new&nbsp;
  								 <input type="radio" name="cover" value="3" class="description" <?php echo $cond2[2];?> />&nbsp;good&nbsp;
   								 <input type="radio" name="cover" value="2" class="description" <?php echo $cond2[1];?> />&nbsp;incomplete&nbsp; 
   								 <input type="radio" name="cover" value="1" class="description" <?php echo $cond2[0];?>  />&nbsp;broken&nbsp;
							</td>
                        </tr>
						<tr>
                        	<td>Page</td>
                        	<td width="50px"></td>
                        	<td>
                        		 <input type="radio" name="page" value="4" class="description"  <?php echo $cond3[3];?> />&nbsp;as new&nbsp;
  								 <input type="radio" name="page" value="3" class="description" <?php echo $cond3[2];?> />&nbsp;good&nbsp;
   								 <input type="radio" name="page" value="2" class="description" <?php echo $cond3[1];?> />&nbsp;incomplete&nbsp;
   								 <input type="radio" name="page" value="1" class="description" <?php echo $cond3[0];?>/>&nbsp;broken&nbsp;
							</td>
                        </tr>
                        <tr>
                        	<td>Overall</td>
                        	<td width="50px"></td>
                        	<td>
                        		 <input type="radio" name="all" value="4" class="description" <?php echo $cond4[0];?> />&nbsp;as new&nbsp;
  								 <input type="radio" name="all" value="3" class="description" <?php echo $cond4[1];?> />&nbsp;good&nbsp;
   								 <input type="radio" name="all" value="2" class="description" <?php echo $cond4[2];?> />&nbsp;incomplete&nbsp;
   								 <input type="radio" name="all" value="1" class="description" <?php echo $cond4[3];?> />&nbsp;broken&nbsp;
							</td>
                        </tr>
                         <tr>
                            <td></td>
                            <td width="50px"></td>
                            <td><input type="submit" value="" id="submit_btn" /></td>
                        </tr>
                    </table>
                    </form>
           		</div>
            </div>
        </div>
    </div>
</div>

<?php
include("footer.php");
?>

